package factory;

import entity.*;

public class CardFactory {
    private static final CreditCard[] cards = {new AmExCC(), new DiscoverCC(), new MasterCC(), new VisaCC()};
    public static CreditCard createCard(String line){
        String[] tokens = line.split(" ", -1);
        if(tokens.length != 2)
            return null;

        for(CreditCard card : cards) {
            if(card.isValid(tokens[0])){
                return card.getInstance().setNumber(tokens[0]).setHolderName(tokens[1]);
            }
        }

        return null;
    }
}
